package com.hhkj.study.admin.article.service.base.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.hhkj.study.admin.article.entity.Article;
import com.hhkj.study.admin.article.mapper.ArticleMapper;
import com.hhkj.study.admin.article.model.podo.ArticleDo;
import com.hhkj.study.admin.article.model.podo.ArticlePo;
import com.hhkj.study.admin.article.service.base.ArticleService;
import com.ruoyi.common.base.biz.service.base.BaseServiceImpl;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.utils.paging.PagingUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class ArticleServiceImpl extends BaseServiceImpl<Article, ArticleDo, ArticlePo, ArticleMapper> implements ArticleService {

    @Override
    public PageInfo<ArticlePo> pagingPoByDo(ArticleDo conditionDo) {
        PageDomain pageDomain = ObjectUtil.isNull(conditionDo.getPageDomain()) ? PageDomain.initPageDomain() : conditionDo.getPageDomain();
        Page<ArticleDo> pageDo = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        List<OrderItem> orderItems = new ArrayList<>();
        orderItems.add(OrderItem.asc(getOrderColumnMap().get("orderNum")));
        orderItems.add(OrderItem.desc(getOrderColumnMap().get("publishTime")));
        orderItems.add(OrderItem.desc(getOrderColumnMap().get("createTime")));
        pageDo.setOrders(orderItems);
        Page<ArticlePo> pagePo = this.getBaseMapper().pagingPoByDo(pageDo, conditionDo);
        return PagingUtils.toPageInfoPo(pagePo);
    }

    @Override
    public Map<String, String> getOrderColumnMap() {
        return new HashMap<String, String>() {{
            put("orderNum", "xa.order_num");
            put("publishTime", "xa.publish_time");
            put("createTime", "xa.create_time");
        }};
    }
}